package org.jeecg.modules.demo.crm.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.constant.ProvinceCityArea;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.modules.demo.crm.entity.CLibrary;
import org.jeecg.modules.demo.crm.entity.CProjectApplication;
import org.jeecg.modules.demo.crm.mapper.CLibraryMapper;
import org.jeecg.modules.demo.crm.mapper.CProjectApplicationMapper;
import org.jeecg.modules.demo.crm.service.ICLibraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 库管理
 * @Author: jeecg-boot
 * @Date:   2025-06-16
 * @Version: V1.0
 */
@Service
public class CLibraryServiceImpl extends ServiceImpl<CLibraryMapper, CLibrary> implements ICLibraryService {

    @Autowired
    CLibraryMapper cLibraryMapper;

    @Autowired
    CProjectApplicationMapper cProjectApplicationMapper;

    @Override
    public CLibrary queryByProjectId(String projectId) {
        CProjectApplication cProjectApplication = cProjectApplicationMapper.selectById(projectId);
        if(cProjectApplication != null && StringUtils.isNotEmpty(cProjectApplication.getLibraryId())){
            CLibrary cLibrary = cLibraryMapper.selectById(cProjectApplication.getLibraryId());
            if(cLibrary != null && StringUtils.isNotEmpty(cLibrary.getCity())){
                String text = SpringContextUtils.getBean(ProvinceCityArea.class).getText(cLibrary.getCity());
                cLibrary.setCity(text);
            }
            return cLibrary;
        }
        return new CLibrary();
    }
}
